/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$(function () {
    $('#tj').click(function () {
        var items = $("input[name=radio1]:checked");
        var flag = false;
        var id = null;
        if (items.length == 0) {
            flag = true;
        } else {
            $("input[name=radio1]:checked").each(function () {
                id = ($(this).val()).split("-")[0];
            });
        }
        if (flag) {
            $.alert("请选择一条数据！");
        } else {
            $.showLoading();
            var o = new AjaxOptions();
            o.put('service_code', 'P90008');
            o.put('id', id);
            o.sus = function (data) {
                $.hideLoading();
                var sj = Math.random();
                $.toast("操作成功");
                window.location.href = window.location.href + sj;
            };
            o.fal = function (code, desc) {
                $.hideLoading();
                $.toast("归还用车失败！", "forbidden");

            };
            $.ajax(o);
        }
    });

    //车辆续用
    $('#xy').click(function () {
        var items = $("input[name=radio1]:checked");
        var flag = false;
        var id = null;
        var sftx = null;//系统是否提醒还车
        if (items.length == 0) {
            flag = true;
        } else {
            $("input[name=radio1]:checked").each(function () {
                id = ($(this).val()).split("-")[0];
                sftx = ($(this).val()).split("-")[1];
            });
        }
        if (flag) {
            $.alert("请选择一条数据！");
        } else {
            if (sftx == null || sftx == "") {
                $.confirm("距用车结束时间超于一天！确认仍续用车辆吗？", function () {
                     $.closeModal();
                    //点击确认后的回调函数
                    $.prompt_date({
                        title: '车辆续用',
                        text: '请输入用车结束时间',
                        input: '',
                        empty: true, // 是否允许为空
                        onOK: function (jsrq) {
                            if (jsrq == "") {
                                $.toast("结束时间不能为空！", "forbidden");
                            } else {
                                $.showLoading();
                                var o = new AjaxOptions();
                                o.put('service_code', 'P90010');
                                o.put('id', id);
                                o.put('jssj', jsrq);
                                o.sus = function (data) {
                                    $.hideLoading();
                                    var sj = Math.random();
                                    $.toast("操作成功");
                                    window.location.href = window.location.href + sj;
                                };
                                o.fal = function (code, desc) {
                                    $.hideLoading();
                                    if (code == "9001001") {
                                        $.toast("车辆续用失败！", "forbidden");
                                    }
                                };
                                $.ajax(o);
                            }
                        },
                        onCancel: function () {

                        }
                    });
                }, function () {
                    $.closeModal();
                });
            } else {
                $.prompt_date({
                    title: '车辆续用',
                    text: '请输入用车结束时间',
                    input: '',
                    empty: true, // 是否允许为空
                    onOK: function (jsrq) {
                        if (jsrq == "") {
                            $.toast("结束时间不能为空！", "forbidden");
                        } else {
                            $.showLoading();
                            var o = new AjaxOptions();
                            o.put('service_code', 'P90010');
                            o.put('id', id);
                            o.put('jssj', jsrq);
                            o.sus = function (data) {
                                $.hideLoading();
                                var sj = Math.random();
                                $.toast("操作成功");
                                window.location.href = window.location.href + sj;
                            };
                            o.fal = function (code, desc) {
                                $.hideLoading();
                                if (code == "9001001") {
                                    $.toast("车辆续用失败！", "forbidden");
                                }
                            };
                            $.ajax(o);
                        }
                    },
                    onCancel: function () {

                    }
                });
            }

        }
    })

});
function xsxq() {
    var items = $("input[name=radio1]:checked");
    if (items.length == 0 || items.length > 1) {
        $.alert("请选择一条数据查看详情");
    } else {
        var id = ($("input[name=radio1]:checked").val()).split("-")[0];
        var o = new AjaxOptions();
        o.put('service_code', 'P90007');
        o.put('id', id);
        o.sus = function (data) {
            var xq = data.xq;
            var kssj = (xq.kssj).substring(0, 16);
            var jssj = (xq.jssj).substring(0, 16);
            var text = "<div class='weui_cell'>" +
                    "<div class='weui_cell_hd'><label style='width: 100px' class='weui_label'>车牌号:</label></div>" +
                    "<div class='weui_cell_bd weui_cell_primary'>" +
                    "<input  class='weui_input' value='" + xq.cph_ + "' readonly='readonly'></div></div>" +
                    "<div class='weui_cell'>" +
                    "<div class='weui_cell_hd'><label style='width: 100px' class='weui_label'>用车人:</label></div>" +
                    "<div class='weui_cell_bd weui_cell_primary'>" +
                    "<input  class='weui_input' value='" + xq.ycr + "'  readonly='readonly'></div></div>" +
                    "<div class='weui_cell'>" +
                    "<div class='weui_cell_hd'><label style='width: 100px' class='weui_label'>用车时间(始):</label></div>" +
                    "<div class='weui_cell_bd weui_cell_primary'>" +
                    "<input  class='weui_input' value='" + kssj + "' readonly='readonly'></div></div>" +
                    "<div class='weui_cell'>" +
                    "<div class='weui_cell_hd'><label style='width: 100px' class='weui_label'>用车时间(终):</label></div>" +
                    "<div class='weui_cell_bd weui_cell_primary'>" +
                    "<input  class='weui_input' value='" + jssj + "' readonly='readonly'></div></div>" +
                    "<div class='weui_cell'>" +
                    "<div class='weui_cell_hd'><label style='width: 100px' class='weui_label'>用&nbsp;&nbsp;&nbsp;&nbsp;途:</label></div>" +
                    "<div class='weui_cell_bd weui_cell_primary'>" +
                    "<input  class='weui_input' value='" + xq.yt + "' readonly='readonly'></div></div>";
            $.modal({
                title: "用车详情",
                text: text,
                autoClose: true,
                buttons: [
                    {text: "关闭", onClick: function () {

                        }},
                ]

            });
            $('.weui_dialog').css('margin-top', '-90px');

        };
        o.fal = function (code, desc) {
            $.toast("获取详情失败！", "forbidden");
        };
        $.ajax(o);
    }
}
// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符， 
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
// 例子： 
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}